
import mx.collections.ArrayCollection;


private function addLocaleBrowseClick():void {
	var myFile:File = new File();
	 
	myFile.addEventListener(Event.SELECT, addLocaleNewFile);
	myFile.browseForSave("Choose locale file name");
}

private function addLocaleNewFile(event:Event):void 
{
    var newFile:File = event.target as File;
    
    if (newFile.extension != "properties") {
    	newFile = new File(newFile.nativePath + ".properties");
    }
    
    if (newFile.exists) {
    	Alert.show("File already exists and will be overwritten when generated.");
    }
    
    alFilename.text = newFile.nativePath;
}

private function createNewLocale():void {
	var newLocale:String = alLocaleCombo.value.toString();
	var x:XML = <locale code="" file="" />;
	
	x.@code = newLocale;
	x.@file = alFilename.text;
	project.appendChild(x.copy());
	
	for each (var e:XML in project.locale.(@code == masterLocale).entry) {
		var ne:XML = <entry name="" text="" suggestion="" translation="" />;
		ne.@name = e.@name;
		project.locale.(@code == newLocale)[0].appendChild(ne.copy());
	} 
	
	projectModified = true;
	
	currentState = "openProject";
}

private function addLocaleEnterState():void {
	var unusedLocales:ArrayCollection = new ArrayCollection();
	for each (var l:String in supportedLocales) {
		if (l != masterLocale) {
			if (!project.locale.@code.contains(l)) {
				unusedLocales.addItem(l);
			}
		}
	}
	alLocaleCombo.dataProvider = unusedLocales;
	alFilename.text = "";
}